﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace BGSpaceShooter
{
    public class ProjectileDrawer : GameObjectDrawer
    {
        private Projectile projectile;

        public ProjectileDrawer(Projectile projectile)
        {
            this.projectile = projectile;
        }

        public override void Draw(Camera camera)
        {
            Matrix modelMatrix = projectile.ModelMatrix;
            Display.GraphicsDevice.RasterizerState = RasterizerState.CullClockwise;

            int i = 0;
            foreach (var model in projectile.Model.Meshes)
            {
                foreach (Effect effect in model.Effects)
                {
                    //Macierze
                    effect.Parameters["xWorld"].SetValue(modelMatrix);
                    effect.Parameters["xView"].SetValue(camera.CameraMatrix);
                    effect.Parameters["xProjection"].SetValue(Display.ProjectionMatrix);

                    effect.Parameters["xEnableLighting"].SetValue(true);
                    effect.Parameters["xLightDirection"].SetValue(new Vector3(0, 0, 1));
                    effect.Parameters["xCameraPosition"].SetValue(camera.CameraPosition);

                    effect.Parameters["xHasTexture"].SetValue(true);
                    effect.Parameters["xAmbient"].SetValue(projectile.Ambient[i] + 0.2f);
                    effect.Parameters["xSpecularFactor"].SetValue(projectile.SpecularFactor[i]);
                    if (projectile.Velocity.Length() > 0)
                        effect.Parameters["xIsBullet"].SetValue(true);
                    effect.Parameters["xTexture"].SetValue(projectile.Textures[i++]);
                }
                model.Draw();
            }
        }

        public override IEnumerable<ParticleSystem.EffectDrawer> GetEffectDrawers()
        {
            return new List<ParticleSystem.EffectDrawer>() { projectile.GetEffectsToDraw().First().GetDrawer() };
        }

    }

}
